package com.ruoyi.quartz.task;

import com.ruoyi.bizsys.domain.CustBankCard;
import com.ruoyi.bizsys.mapper.CustBankCardMapper;
import com.ruoyi.common.utils.spring.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Component("bindCardPollingTask")
public class BindCardPollingTask {

    @Resource
    CustBankCardMapper custBankCardMapper;
    /**
     * 查询绑卡有效期时间
     */
    public void executeBindCard() {
        log.info("执行绑卡有效期时间任务");
        //查询绑卡记录中的绑卡失效记录
        List<CustBankCard> custBankCards = custBankCardMapper.selectBindCardPeriod();
        if(custBankCards == null && custBankCards.size() == 0){
            return;
        }
        //取出list集合修改卡片状态
        List<CustBankCard> list = new ArrayList<>();
        for (int i = 0; i < custBankCards.size(); i++) {
            CustBankCard custBankCard = custBankCards.get(i);
            //设置失效状态为0
            custBankCard.setCardStatus("0");
            list.add(custBankCard);
            //list 集合 分批执行入库
            if (list.size() % 1000 == 0 || i == custBankCards.size()-1) {
                //执行轮训任务
                log.info("执行批量插入操作");
                int result = SpringUtils.getBean(CustBankCardMapper.class).updateBatch(custBankCards);
                log.info("----- updateBatch bindCardTask : " + result);
            }
        }
        log.info("每月绑卡定时任务执行完毕");
    }
}